<template>
  <!--  发货单明细页面  -->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search :config="searchConfig" @search="search" @getHeight="getHeight"/>

    <!-- table区域-begin -->
    <div class="page_table">
      <vxe-grid
        ref="xGrid"
        :border="true"
        :resizable="true"
        :showOverflow="true"
        size="mini"
        :loading="loading"
        :height="pageHeight-seachHeight-94"
        :align="left"
        :columns="columns"
        :data="dataSource"
        :toolbar-config="tableToolbar"
        :checkbox-config="checkboxConfig"
        v-bind="vexConfig"
        @checkbox-change="selectChangeEvent"
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <!-- 操作按钮区域 -->
          <div class="table-operator">
            <a-button @click="downExportXls('dms_order_report_service')">导出</a-button>
          </div>
        </template>
        <template #deliveryMethod="{ row,rowIndex }">
          {{ filterDictText(statusList, row.deliveryMethod) }}
        </template>
        <template #dataType="{ row,rowIndex }">
          {{ filterDictText(sourceList, row.dataType) }}
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync="ipagination.current"
            :page-size.sync="ipagination.pageSize"
            :total="ipagination.total"
            :pageSizes="ipagination.pageSizeOptions"
            @page-change="handlePageChange">
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>

    <business-log ref="businessLog"></business-log>
  </a-card>
</template>

<script>
import ordermgtModal from './TerminalOrderModal/ordermgtModal.vue'
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction, postAction } from '@api/manage'
import Vue from 'vue'
import { initDictOptions, filterDictText } from '@comp/dict/CnDictSelectUtil'

export default {
  name: 'InvoiceDetails',
  mixins: [PageListMixin],
  components: {},
  data() {
    return {
      selectedRowKeys: [],
      description: '订单明细',
      statusList: [],
      sourceList: [], // 订单来源字典
      searchConfig: [
        {
          type: 'input',
          name: 'orderCode',
          placeholder: ' 订单编号'
        },
        {
          type: 'input',
          name: 'customerCode',
          placeholder: ' 客户编号'
        },
        {
          type: 'input',
          name: 'customerName',
          placeholder: ' 客户名称'
        },

      ],
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      defColumns: [
        { type: 'checkbox', width: 60, fixed: 'left' },
        {
          title: '订单编号',
          align: 'left',
          field: 'orderCode',
          minWidth: 110,
        },
        {
          title: 'OMS订单编号',
          align: 'left',
          field: 'omsOrderCode',
          minWidth: 100,
        },
        {
          title: '原始订单号',
          align: 'left',
          field: 'originalCode',
          minWidth: 80,
        },
        {
          title: '客户编号',
          align: 'left',
          field: 'customerCode',
          minWidth: 80,
        },
        {
          title: '客户名称',
          align: 'left',
          field: 'customerName',
          minWidth: 80,
        },
        {
          title: '提货方式',
          align: 'left',
          field: 'deliveryMethod',
          minWidth: 80,
          slots: { default: 'deliveryMethod' }
        }
        , {
          title: '提货点编号',
          align: 'left',
          field: 'pupCode',
          minWidth: 80,
        },
        , {
          title: '提货点名称',
          align: 'left',
          field: 'pupName',
          minWidth: 100,
        }, , {
          title: '收货地址',
          align: 'left',
          field: 'addressDetailed',
          minWidth: 120,
        }, , {
          title: '联系人',
          align: 'left',
          field: 'consignee',
          minWidth: 80,
        }, , {
          title: '联系方式',
          align: 'left',
          field: 'consigneeCall',
          minWidth: 80,
        }, , {
          title: '物流模式',
          align: 'left',
          field: 'logisticsPatternName',
          minWidth: 80,
        },
        , {
          title: '行号',
          align: 'left',
          field: 'posnr',
          minWidth: 80,
        },
        , {
          title: '行类型',
          align: 'left',
          field: 'dataType',
          minWidth: 80,
          slots: { default: 'dataType' }
        },
        , {
          title: '规则编号',
          align: 'left',
          field: 'promotionCode',
          minWidth: 80,
        },
        // ,{
        //   title: '规则名称',
        //   align: 'left',
        //   field: 'promotionName',
        //   minWidth: 80,
        // },
        , {
          title: '商品编号',
          align: 'left',
          field: 'productCode',
          minWidth: 120,
        },
        {
          title: '商品名称',
          align: 'left',
          minWidth: 120,
          field: 'goodsName'
        },
        , {
          title: '批次开始时间',
          align: 'left',
          field: 'batchStratDate',
          minWidth: 100,
        },
        {
          title: '批次结束时间',
          align: 'left',
          minWidth: 100,
          field: 'batchEndDate'
        },
        , {
          title: '单位',
          align: 'left',
          field: 'unitDesc',
          minWidth: 80,
        },
        {
          title: '价格',
          align: 'left',
          minWidth: 80,
          field: 'originalPrice'
        },
        {
          title: '下单数量',
          align: 'left',
          minWidth: 80,
          field: 'quantity'
        },
      ],
      isorter: {
        permflag: 'order_detail_page_impl'
      },
      url: {
        list: window._CONFIG['domianDmsURL'] + '/order/orderReport/findOrderDetailPageList',
        // detail: window._CONFIG['domianURL'] + '/userorgrelation/cnUserOrgRelation/saveOrUpdate',
        // edit: window._CONFIG['domianURL'] + '/mdsProduct/saveOrUpdateEntity',
        // deleteBatch: '/userorgrelation/cnUserOrgRelation/deleteBatch',
        // delete: window._CONFIG['domianURL'] + '/userorgrelation/cnUserOrgRelation/delete',
        // exportXlsUrl: window._CONFIG['domianTpmURL'] + 'budget/tpmBudgetFee/exportXls'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.initColumns()
  },
  methods: {
    filterDictText,
    initDictConfig() {
      initDictOptions('delivery_method').then((res) => {
        if (res.success) {
          this.statusList = res.result
        }
        console.log('字典', this.sourceList)
      })
      initDictOptions('line_type').then((res) => {
        if (res.success) {
          this.sourceList = res.result
        }
      })
    },
    //列表设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter(item => {
        if (item.key == 'rowIndex' || item.field == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.field)) {
          return true
        }
        return false
      })
      this.columns = cols
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    changeStatus(e, item) {
      if (e) {
        this.startorstopByid(1, item.id)
      } else {
        this.startorstopByid(0, item.id)
      }
    },
    startorstopByid(status, id) {
      let that = this
      this.$confirm({
        title: '确认修改',
        content: '是否' + (status == 0 ? '停用' : '启动') + '选中数据？',
        onOk() {
          that.loading = true
          getAction(that.url.startOrStopUrl, { ids: id, status: status }).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
              that.onClearSelected()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.loading = false
          })
        },
        onCancel() {
          // that.loadData();
          // that.onClearSelected();
        },
      })
    },
    handleEdit: async function (row) {

      this.$refs.modalForm.edit(row)
      this.$refs.modalForm.disableSubmit = false
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');
      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.field)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.field == 'action') {
            return true
          }
          if (colSettings.includes(item.field)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
  }
}
</script>


<style scoped>
@import '~@assets/less/common.less';
</style>
